package com.jxd.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jxd.dao.EmployeeMapper;
import com.jxd.model.Employee;
import com.jxd.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class EmployeeServiceImpl
        extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;


    @Override
    public Map<String, Object> getAllEmpList(Map<String, String> queryMap) {
        String page = queryMap.get("page");
        String limit = queryMap.get("limit");
        String name = queryMap.get("name");

        Map<String, Object> map = new HashMap(4);
        if (page != null && limit != null) {
            IPage<Employee> pages = new Page(Integer.parseInt(page), Integer.parseInt(limit));
            IPage<Employee> pageResult = employeeMapper.getAllEmpList(pages, name);
            map.put("count", pageResult.getTotal());
            map.put("data", pageResult.getRecords());
            map.put("code", 0);
            return map;
        } else {
            map.put("data", (Object) null);
            map.put("code", "500");
            map.put("msg", "参数不符");
            map.put("count", (Object) null);
            return map;
        }

    }
}
